/******************************************************************************
 * * setting_call.c - implementation of call setting functions
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/

#include "setting_global.h"

Setting_Call_Setting_Mng_t    g_SettingCallSettingMng;                          // for call setting management
VOID                          *gp_SettingCallSettingCurUIDesc        = NULL;    // Current UI description
VOID                          *gp_SettingCallSettingCurContLstUIDesc = NULL;    // Current Setting Call ettings UI description
UINT8                         g_SettingCallDivertNumberTaRestCharacters;        // Call divert screen, rest characters in text area can be input
UINT8                         g_SettingCallDivertNoAnswerDelayTime = 0;         // Call divert screen, store "divert if no answer" delay time
extern const INT8             g_SettingAcceptedCharsForNumberInput[11];         // used for setting divert number valid chars can be accepted
MMI_Modem_Call_Forward_Info_t g_SettingCallDivertCheckStatusResult;             // store result of divert "check status" operation
UINT8                         g_SettingCallWaitStatus[2]    = { 0xFF, 0xFF };   // 1: ON, 0: OFF, 0xFF:Not checked
UINT8                         g_SettingCallWaitWaitQueryCnf = 0;                // bitmap, 0x01: SIM1 wait flag, 0x02: SIM2 wait flag

/**
 * sub-module entry
 * param (in) void
 * return  void
 */
VOID Setting_Call_Main(VOID)
{
    // init manage variable
}

/**
 * sub-module event handler
 * param (in) void
 * return  void
 */
VOID Setting_Call_Event_handle(VOID)
{
    // event and message dispatch
}

/**
 * initiate call sub-module
 * param (in) pNvPara: NV_UI_Settings_t
 * return  void
 */
VOID Setting_Call_Init_Req(NV_UI_Settings_t *pNvPara)
{
    // init manage variable
    g_SettingCallSettingMng.AutoRedialOn = pNvPara->CallSetting.AutoRedialOn;
}

/**
 * Get redial on/off configuration
 * param (in) void
 * return  BOOL: true means redial on.
 */
BOOL Setting_Get_Redial_config_Req(VOID)
{
    return(g_SettingCallSettingMng.AutoRedialOn);
}

/**
 * Set operation sim ID
 * param (in) OperationSimId: MMI_MODEM_SIM_ID
 * return void:
 */
VOID Setting_Set_Operation_Sim_Id(MMI_MODEM_SIM_ID OperationSimId)
{
    // change global variable
    g_SettingCallSettingMng.OperationSimId = OperationSimId;
}

/**
 * Set operation SS service
 * param (in) OperatingSS: SETTING_SS_SERVICE_TYPE
 * return void:
 */
VOID Setting_Set_Operating_Ss(SETTING_SS_SERVICE_TYPE OperatingSS)
{
    // change global variable
    g_SettingCallSettingMng.OperatingSS = OperatingSS;
}

/**
 * Set operation SS service action type
 * param (in) OperatingAction: SETTING_CALL_DIVERT_ACTION_TYPE
 * return void:
 */
VOID Setting_Set_Operating_Ss_Action(SETTING_CALL_DIVERT_ACTION_TYPE OperatingAction)
{
    // change global variable
    g_SettingCallSettingMng.OperatingAction = OperatingAction;
}

/**
 * Set redial on/off configuration
 * param (in) AutoRedialOn: BOOL
 * return void:
 */
VOID Setting_Set_Redial_Config(BOOL AutoRedialOn)
{
    UINT8 nvData;

    // change global variable
    g_SettingCallSettingMng.AutoRedialOn = AutoRedialOn;

    // nv write
    nvData = g_SettingCallSettingMng.AutoRedialOn;
    UI_NV_Write_Req(NV_SECTION_UI_SETTINGS, NV_SETTING_CALL_SETTING_OFFSET, NV_SETTING_CALL_SETTING_LEN, &nvData);
}

/**
 * Callback of Setting_Call_Divert_Delay_Time, 5s
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Divert_Delay_Time_5s_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        g_SettingCallDivertNoAnswerDelayTime = 5;
        Display_Setting_Done(ACT_ID_SETTING_CALL_DIVERT_DELAY_TIME,PHONE_TEXT_ID_DELAY_TIME_SELECTED,ACT_ID_SETTING_CALL_DIVERT);
    }
}

/**
 * Callback of Setting_Call_Divert_Delay_Time, 10s
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Divert_Delay_Time_10s_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        g_SettingCallDivertNoAnswerDelayTime = 10;
        Display_Setting_Done(ACT_ID_SETTING_CALL_DIVERT_DELAY_TIME,PHONE_TEXT_ID_DELAY_TIME_SELECTED,ACT_ID_SETTING_CALL_DIVERT);
    }
}

/**
 * Callback of Setting_Call_Divert_Delay_Time, 15s
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Divert_Delay_Time_15s_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        g_SettingCallDivertNoAnswerDelayTime = 15;
        Display_Setting_Done(ACT_ID_SETTING_CALL_DIVERT_DELAY_TIME,PHONE_TEXT_ID_DELAY_TIME_SELECTED,ACT_ID_SETTING_CALL_DIVERT);
    }
}

/**
 * Callback of Setting_Call_Divert_Delay_Time, 20s
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Divert_Delay_Time_20s_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {        
        g_SettingCallDivertNoAnswerDelayTime = 20;
        Display_Setting_Done(ACT_ID_SETTING_CALL_DIVERT_DELAY_TIME,PHONE_TEXT_ID_DELAY_TIME_SELECTED,ACT_ID_SETTING_CALL_DIVERT);
    }
}

/**
 * Callback of Setting_Call_Divert_Delay_Time, 25s
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Divert_Delay_Time_25s_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        g_SettingCallDivertNoAnswerDelayTime = 25;
        Display_Setting_Done(ACT_ID_SETTING_CALL_DIVERT_DELAY_TIME,PHONE_TEXT_ID_DELAY_TIME_SELECTED,ACT_ID_SETTING_CALL_DIVERT);
    }
}

/**
 * Callback of Setting_Call_Divert_Delay_Time, 30s
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Divert_Delay_Time_30s_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        g_SettingCallDivertNoAnswerDelayTime = 30;
        Display_Setting_Done(ACT_ID_SETTING_CALL_DIVERT_DELAY_TIME,PHONE_TEXT_ID_DELAY_TIME_SELECTED,ACT_ID_SETTING_CALL_DIVERT);
    }
}

/**
 *
 * Callback of Setting_Call_Divert_Delay_Time, on destroy
 * param (in) NormalLstOnlyDesc: UI_Normal_List_Only_Desc_t*
 * return void:
 */
VOID Display_Setting_Call_Divert_Delay_Time_Destroy(VOID *pPara)
{
    UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc = NULL;

    NormalLstOnlyDesc = (UI_Normal_List_Only_Desc_t *)pPara;

    Hal_Mem_Free(NormalLstOnlyDesc->List.ButtonList);
    Hal_Mem_Free(NormalLstOnlyDesc);
}

/**
 *
 * Callback of Setting_Call_Divert_Delay_Time, KeyCb
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Call_Divert_Delay_Time_KeyCb(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    if (KEY_RELEASED != key_sta)
    {
        return(0);
    }

    if (KEY_SOFTRIGHT == key_val)
    {
        Nav_Back(ACT_ID_SETTING_CALL_DIVERT_DELAY_TIME);
        return(1);
    }
    else if (KEY_END == key_val)
    {
        Nav_Home(ACT_ID_ANY);
        return(1);
    }
    else
    {
        return(0);
    }
}

/**
 * display Setting_Call_Divert_Delay_Time
 * param (in) void:
 * return void:
 */
VOID Display_Setting_Call_Divert_Delay_Time(VOID)
{
    //
    UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc;
    Nav_Func_List_t            FuncList;

    NormalLstOnlyDesc = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(NormalLstOnlyDesc, 0, sizeof(UI_Normal_List_Only_Desc_t));

    NormalLstOnlyDesc->TitleBar.TxtId      = PHONE_TEXT_ID_SELECT_DELAY_TIME;
    NormalLstOnlyDesc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    NormalLstOnlyDesc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    NormalLstOnlyDesc->List.Index         = 0;
    NormalLstOnlyDesc->List.ListButtonCnt = 6;
    NormalLstOnlyDesc->List.ButtonList    = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * 6);
    Hal_Mem_Set(NormalLstOnlyDesc->List.ButtonList, 0, sizeof(UI_Button_Desc_t) * 6);

    NormalLstOnlyDesc->List.ButtonList[0].ButtonIndex = 0;
    NormalLstOnlyDesc->List.ButtonList[0].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[0].TxtId       = PHONE_TEXT_ID_5SEC;
    NormalLstOnlyDesc->List.ButtonList[0].ReleaseFun  = Display_Setting_Call_Divert_Delay_Time_5s_Cb;
    NormalLstOnlyDesc->List.ButtonList[1].ButtonIndex = 1;
    NormalLstOnlyDesc->List.ButtonList[1].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[1].TxtId       = PHONE_TEXT_ID_10SEC;
    NormalLstOnlyDesc->List.ButtonList[1].ReleaseFun  = Display_Setting_Call_Divert_Delay_Time_10s_Cb;
    NormalLstOnlyDesc->List.ButtonList[2].ButtonIndex = 2;
    NormalLstOnlyDesc->List.ButtonList[2].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[2].TxtId       = PHONE_TEXT_ID_15SEC;
    NormalLstOnlyDesc->List.ButtonList[2].ReleaseFun  = Display_Setting_Call_Divert_Delay_Time_15s_Cb;
    NormalLstOnlyDesc->List.ButtonList[3].ButtonIndex = 3;
    NormalLstOnlyDesc->List.ButtonList[3].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[3].TxtId       = PHONE_TEXT_ID_20SEC;
    NormalLstOnlyDesc->List.ButtonList[3].ReleaseFun  = Display_Setting_Call_Divert_Delay_Time_20s_Cb;
    NormalLstOnlyDesc->List.ButtonList[4].ButtonIndex = 4;
    NormalLstOnlyDesc->List.ButtonList[4].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[4].TxtId       = PHONE_TEXT_ID_25SEC;
    NormalLstOnlyDesc->List.ButtonList[4].ReleaseFun  = Display_Setting_Call_Divert_Delay_Time_25s_Cb;
    NormalLstOnlyDesc->List.ButtonList[5].ButtonIndex = 5;
    NormalLstOnlyDesc->List.ButtonList[5].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[5].TxtId       = PHONE_TEXT_ID_30SEC;
    NormalLstOnlyDesc->List.ButtonList[5].ReleaseFun  = Display_Setting_Call_Divert_Delay_Time_30s_Cb;

    NormalLstOnlyDesc->BtnBar.ButtonL.Valid = FALSE;
    NormalLstOnlyDesc->BtnBar.ButtonM.Valid = TRUE;
    NormalLstOnlyDesc->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    NormalLstOnlyDesc->BtnBar.ButtonR.Valid = TRUE;
    NormalLstOnlyDesc->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    NormalLstOnlyDesc->KeyFunc = Display_Setting_Call_Divert_Delay_Time_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow    = UI_Normal_List_Only_Create;
    FuncList.OnDestroy = Display_Setting_Call_Divert_Delay_Time_Destroy;

    Nav_Forward(ACT_ID_SETTING_CALL_DIVERT_ACTION,ACT_ID_SETTING_CALL_DIVERT_DELAY_TIME, &FuncList, (VOID *)NormalLstOnlyDesc);
} /* Display_Setting_Call_Divert_Delay_Time */

/**
 *
 * Callback of Settings_Call_Divert_To, on create
 * param (in) NormalLblOnlyDesc: UI_Normal_Label_Only_Desc_t*
 * return void:
 */
VOID Display_Setting_Call_Divert_To_Create(VOID *pPara)
{
    INT8                        LabelValue[100];
    UINT8                       LabelLen;
    UINT8                       TextLen;
    UI_Normal_Label_Only_Desc_t *NormalLblOnlyDesc = NULL;

    NormalLblOnlyDesc = (UI_Normal_Label_Only_Desc_t *)pPara;

    Hal_Mem_Set(LabelValue, 0, 100);
    strcpy(LabelValue, lv_lang_get_text(PHONE_TEXT_ID_CALL_DIVERT_TO));
    LabelLen               = strlen(LabelValue);
    LabelValue[LabelLen++] = ':';
    LabelValue[LabelLen++] = 0x0A;  // '\n'

    TextLen = strlen(g_SettingCallDivertCheckStatusResult.DestNum);
    memcpy(&LabelValue[LabelLen], g_SettingCallDivertCheckStatusResult.DestNum, TextLen);
    LabelLen += TextLen;

    lv_label_set_text(NormalLblOnlyDesc->ContLabel.Label, LabelValue);
}

/**
 *
 * Callback of Settings_Call_Divert_To, on destroy
 * param (in) NormalLblOnlyDesc: UI_Normal_Label_Only_Desc_t*
 * return void:
 */
VOID Display_Setting_Call_Divert_To_Destroy(VOID *NormalLblOnlyDesc)
{
    Hal_Mem_Free(NormalLblOnlyDesc);
}

/**
 *
 * Callback of Setting_Call_Divert, KeyCb
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Call_Divert_To_KeyCb(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    if (KEY_RELEASED != key_sta)
    {
        return(0);
    }

    if (KEY_OK == key_val)
    {
        Nav_Back(ACT_ID_SETTING_CALL_DIVERT_TO);
        return(1);
    }
    else if (KEY_END == key_val)
    {
        Nav_Home(ACT_ID_ANY);
        return(1);
    }
    else
    {
        return(0);
    }
}

/**
 * display Settings_Call_Divert_To
 * param (in) CallForwardInfo: MMI_Modem_Call_Forward_Info_t*
 * return void:
 */
VOID Display_Setting_Call_Divert_To(MMI_Modem_Call_Forward_Info_t *CallForwardInfo)
{
    UI_Normal_Label_Only_Desc_t *NormalLblOnlyDesc;
    Nav_Func_List_t             FuncList;

    NormalLblOnlyDesc = (UI_Normal_Label_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_Label_Only_Desc_t));
    Hal_Mem_Set(NormalLblOnlyDesc, 0, sizeof(UI_Normal_Label_Only_Desc_t));

    NormalLblOnlyDesc->TitleBar.TxtId      = PHONE_TEXT_ID_CALL_DIVERT_TO;
    NormalLblOnlyDesc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    NormalLblOnlyDesc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    NormalLblOnlyDesc->ContLabel.TxtId      = PHONE_TEXT_ID_CALL_DIVERT_TO;
    NormalLblOnlyDesc->ContLabel.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    NormalLblOnlyDesc->ContLabel.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    NormalLblOnlyDesc->ButtonBar.ButtonL.Valid = FALSE;
    NormalLblOnlyDesc->ButtonBar.ButtonM.Valid = TRUE;
    NormalLblOnlyDesc->ButtonBar.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    NormalLblOnlyDesc->ButtonBar.ButtonR.Valid = FALSE;

    NormalLblOnlyDesc->KeyFunc = Display_Setting_Call_Divert_To_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow    = UI_Normal_Label_Only_Create;
    FuncList.OnCreate  = Display_Setting_Call_Divert_To_Create;
    FuncList.OnDestroy = Display_Setting_Call_Divert_To_Destroy;

    Hal_Mem_Copy(&g_SettingCallDivertCheckStatusResult, CallForwardInfo, sizeof(MMI_Modem_Call_Forward_Info_t));
    Hal_Mem_Free(CallForwardInfo);
    gp_SettingCallSettingCurUIDesc = (VOID *)NormalLblOnlyDesc;
    Nav_Forward(ACT_ID_SETTING_CALL_DIVERT_ACTION,ACT_ID_SETTING_CALL_DIVERT_TO, &FuncList, (VOID *)NormalLblOnlyDesc);
}

/**
 * query SS service call wait confirm
 * param (in) SimId : MMI_MODEM_SIM_ID
 *       (in) Result : MMI_MODEM_RESULT
 * return void
 */
VOID Phone_Modem_Call_Forward_Set_Cnf(MMI_MODEM_SIM_ID SimId, MMI_MODEM_RESULT Result)
{
    ACTIVITY_ID CallerActId;

    // Diverts activate or cancel cases
    if (SETTING_DIVERT_CANCEL_ALL != g_SettingCallSettingMng.OperatingSS)
    {
        // set caller ACT ID in which Forward_Set_req sent
        if (SETTING_DIVERT_ACTION_ACTIVE == g_SettingCallSettingMng.OperatingAction)
        {
            CallerActId = ACT_ID_SETTING_CALL_DIVERT_NUMBER;
        }
        else if (SETTING_DIVERT_ACTION_CANCEL == g_SettingCallSettingMng.OperatingAction)
        {
            CallerActId = ACT_ID_SETTING_CALL_DIVERT_ACTION;
        }

        if (MMI_MODEM_ERROR == Result)
        {
            Display_Setting_Error(CallerActId, PHONE_TEXT_ID_NOT_COMPLETED, ACT_ID_SETTING_CALL_DIVERT_ACTION, TRUE);
        }
        else
        {
            Display_Setting_Done(CallerActId, PHONE_TEXT_ID_DONE, ACT_ID_SETTING_CALL_DIVERT_ACTION);
        }
    }
    // Cancel all diverts case
    else
    {
        if (MMI_MODEM_ERROR == Result)
        {
            Display_Setting_Error(ACT_ID_SETTING_CALL_DIVERT, PHONE_TEXT_ID_NOT_COMPLETED, ACT_ID_SETTING_CALL_DIVERT, TRUE);
        }
        else
        {
            Display_Setting_Done(ACT_ID_SETTING_CALL_DIVERT, PHONE_TEXT_ID_DONE, ACT_ID_SETTING_CALL_DIVERT);
        }
    }
}

/**
 * query SS service call wait confirm
 * param (in) SimId : MMI_MODEM_SIM_ID
 *       (in) Result : MMI_MODEM_RESULT
 *       (in) CallForwardInfo : MMI_Modem_Call_Forward_Info_t(response of check status)
 * return void
 */
VOID Phone_Modem_Call_Forward_Query_Cnf(MMI_MODEM_SIM_ID SimId, MMI_MODEM_RESULT Result, MMI_Modem_Call_Forward_Info_t *CallForwardInfo)
{
    if (MMI_MODEM_ERROR == Result)
    {
        Display_Setting_Error(ACT_ID_SETTING_CALL_DIVERT_ACTION,PHONE_TEXT_ID_NOT_COMPLETED,ACT_ID_SETTING_CALL_DIVERT_ACTION,TRUE);
    }
    else
    {
        // service activated
        if (TRUE == CallForwardInfo->CallForwardOn)
        {
            Display_Setting_Call_Divert_To(CallForwardInfo);
        }
        // service not active
        else
        {
            Display_Setting_Done(ACT_ID_SETTING_CALL_DIVERT_ACTION,PHONE_TEXT_ID_SERVICE_NOT_ACTIVE,ACT_ID_SETTING_CALL_DIVERT_ACTION);
            Hal_Mem_Free(CallForwardInfo);
        }
    }
}

/**
 * Inform Setting APP of the contact selected in contacts APP
 * param (in) Number: INT8*
 * return  void
 */
VOID Contacts_Setting_Select_Contact_Cnf(INT8 *Number)
{
    UINT8                             NumberLen;

    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc;

    NormalNoTitleLblTaDesc = (UI_Normal_NoTitle_Label_Ta_Desc_t *)gp_SettingCallSettingCurUIDesc;

    // Update & store rest characters
    NumberLen                                 = strlen(Number);
    g_SettingCallDivertNumberTaRestCharacters = NV_CONTACTS_MAX_NUMBER_LEN - NumberLen;

    // Store numbers from contact
    NormalNoTitleLblTaDesc->ContTa.TaTxt = (INT8 *)Hal_Mem_Alloc(NumberLen);
    Hal_Mem_Set(NormalNoTitleLblTaDesc->ContTa.TaTxt, 0, NumberLen);
    Hal_Mem_Copy(NormalNoTitleLblTaDesc->ContTa.TaTxt, Number, NumberLen);

    Hal_Mem_Free(Number);

    // Return to Setting_Call_Divert_Number screen
    // Nav_Back(ACT_ID_SETTING_CALL_DIVERT_NUMBER);
    Nav_Back(ACT_ID_ANY);
}

/**
 *
 * Callback of Settings_Call_Divert_Number, on create
 * param (in) NormalNoTitleLblTaDesc: UI_Normal_NoTitle_Label_Ta_Desc_t*
 * return void:
 */
VOID Display_Setting_Call_Divert_Number_Create(VOID *pPara)
{
    INT8                              LabelValue[3]           = { 0, 0, 0 };
    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc = NULL;

    NormalNoTitleLblTaDesc                    = (UI_Normal_NoTitle_Label_Ta_Desc_t *)pPara;
    g_SettingCallDivertNumberTaRestCharacters = NV_CONTACTS_MAX_NUMBER_LEN;

    // Update the rest input characters on count label
    if (g_SettingCallDivertNumberTaRestCharacters > 9)
    {
        LabelValue[0] = g_SettingCallDivertNumberTaRestCharacters / 10 + 0x30;
        LabelValue[1] = g_SettingCallDivertNumberTaRestCharacters % 10 + 0x30;
    }
    else
    {
        LabelValue[0] = g_SettingCallDivertNumberTaRestCharacters + 0x30;
    }
    lv_label_set_text(NormalNoTitleLblTaDesc->ContLabelTr.Label, LabelValue);

    // set max length of TA
    lv_textarea_set_max_length(NormalNoTitleLblTaDesc->ContTa.TextArea, NV_CONTACTS_MAX_NUMBER_LEN);

    // set valid characters acceptable as input number
    lv_textarea_set_accepted_chars(NormalNoTitleLblTaDesc->ContTa.TextArea, g_SettingAcceptedCharsForNumberInput);

    Ime_Set_Mode(LV_IME_MODE_NUM);
    Ime_Set_SingleMode(TRUE);
}

/**
 *
 * Callback of Setting_Call_Divert_Number, on destroy
 * param (in) pPara: VOID *
 * return void:
 */
VOID Display_Setting_Call_Divert_Number_Destroy(VOID *pPara)
{
    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc = NULL;

    NormalNoTitleLblTaDesc = (UI_Normal_NoTitle_Label_Ta_Desc_t *)pPara;

    Hal_Mem_Free(NormalNoTitleLblTaDesc->ContTa.TaTxt);
    Hal_Mem_Free(NormalNoTitleLblTaDesc);
}

/**
 *
 * Callback of Settings_Dual_Sim_Name_Edit, on save state
 * param (in) pPara: VOID *
 * return void:
 */
VOID Display_Setting_Call_Divert_Number_SaveState(VOID *pPara)
{
    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc = NULL;
    INT8                              *Text                   = NULL;
    UINT8                             Len                     = 0;

    NormalNoTitleLblTaDesc = (UI_Normal_NoTitle_Label_Ta_Desc_t *)pPara;
    Hal_Mem_Set(NormalNoTitleLblTaDesc->ContTa.TaTxt, 0, NV_CONTACTS_MAX_NUMBER_LEN);
    Text = (INT8 *)lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea);
    Len  = strlen(Text);
    if (0 != Len)
    {
        Hal_Mem_Copy(NormalNoTitleLblTaDesc->ContTa.TaTxt, Text, Len);
    }
}

/**
 *
 * Callback of Settings_Dual_Sim_Name_Edit, on restore state
 * param (in) NormalNoTitleLblTaDesc: UI_Normal_NoTitle_Label_Ta_Desc_t*
 * return void:
 */
VOID Display_Setting_Call_Divert_Number_RestoreState(VOID *pPara)
{
    INT8                              LabelValue[3]           = { 0, 0, 0 };
    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc = NULL;

    NormalNoTitleLblTaDesc = (UI_Normal_NoTitle_Label_Ta_Desc_t *)pPara;

    // Update the rest input characters on count label
    if (g_SettingCallDivertNumberTaRestCharacters > 9)
    {
        LabelValue[0] = g_SettingCallDivertNumberTaRestCharacters / 10 + 0x30;
        LabelValue[1] = g_SettingCallDivertNumberTaRestCharacters % 10 + 0x30;
    }
    else
    {
        LabelValue[0] = g_SettingCallDivertNumberTaRestCharacters + 0x30;
    }
    lv_label_set_text(NormalNoTitleLblTaDesc->ContLabelTr.Label, LabelValue);

    // Update middle key
    if (g_SettingCallDivertNumberTaRestCharacters < NV_CONTACTS_MAX_NUMBER_LEN)
    {
        NormalNoTitleLblTaDesc->ButtonCont.ButtonM.TxtId = PHONE_TEXT_ID_OK;
        lv_label_set_text(lv_obj_get_child(NormalNoTitleLblTaDesc->ButtonCont.ButtonM.Button, NULL),(INT8 *)lv_lang_get_text(PHONE_TEXT_ID_OK));
    }

    Ime_Set_Mode(LV_IME_MODE_NUM);
    Ime_Set_SingleMode(TRUE);
}

/**
 *
 * Callback of Settings_Call_Divert_Number, KeyCb
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Call_Divert_Number_KeyCb(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    INT8                              LabelValue[3] = { 0, 0, 0 };

    MMI_Modem_Call_Forward_Info_t     *CallForwardInfo;

    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc;

    NormalNoTitleLblTaDesc = (UI_Normal_NoTitle_Label_Ta_Desc_t *)gp_SettingCallSettingCurUIDesc;

    if (KEY_RELEASED != key_sta)
    {
        return(0);
    }

    switch (key_val)
    {
    case KEY_OK:
        // When TA is empty, the middle key is "SEARCH"
        if (NV_CONTACTS_MAX_NUMBER_LEN == g_SettingCallDivertNumberTaRestCharacters)
        {
            // Goto contacts main screen
            Contacts_Select_Contact_Req(IF_CONTACTS_SETTING_SEL_ONE_CONTACT);
            return(1);
        }
        // the middle key is "OK"
        else
        {
            CallForwardInfo = (MMI_Modem_Call_Forward_Info_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Call_Forward_Info_t));

            // Copy the number
            Hal_Mem_Copy(CallForwardInfo->DestNum, lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea),NV_CONTACTS_MAX_NUMBER_LEN - g_SettingCallDivertNumberTaRestCharacters);

            // Send command to modem
            CallForwardInfo->CallForwardOn = TRUE;
            if (SETTING_DIVERT_NO_CONDITION == g_SettingCallSettingMng.OperatingSS)
            {
                CallForwardInfo->CallForwardType = MMI_MODEM_CALL_FORWARD_NO_CONDITION;
            }
            else if (SETTING_DIVERT_IF_BUSY == g_SettingCallSettingMng.OperatingSS)
            {
                CallForwardInfo->CallForwardType = MMI_MODEM_CALL_FORWARD_BUSY;
            }
            else if (SETTING_DIVERT_IF_NOT_REACH == g_SettingCallSettingMng.OperatingSS)
            {
                CallForwardInfo->CallForwardType = MMI_MODEM_CALL_FORWARD_NOT_REACH;
            }
            else if (SETTING_DIVERT_IF_NO_ANSWER == g_SettingCallSettingMng.OperatingSS)
            {
                CallForwardInfo->CallForwardType = MMI_MODEM_CALL_FORWARD_NO_ANSWER;
                CallForwardInfo->NoAnswerDelay   = g_SettingCallDivertNoAnswerDelayTime;
            }
            MMI_Modem_Call_Forward_Set_Req(g_SettingCallSettingMng.OperationSimId, CallForwardInfo);
        }
        return(1);

    case KEY_SOFTRIGHT:     // CLEAR
        if (g_SettingCallDivertNumberTaRestCharacters < NV_CONTACTS_MAX_NUMBER_LEN)
        {
            g_SettingCallDivertNumberTaRestCharacters++;
            if (g_SettingCallDivertNumberTaRestCharacters > 9)
            {
                LabelValue[0] = g_SettingCallDivertNumberTaRestCharacters / 10 + 0x30;
                LabelValue[1] = g_SettingCallDivertNumberTaRestCharacters % 10 + 0x30;
            }
            else
            {
                LabelValue[0] = g_SettingCallDivertNumberTaRestCharacters + 0x30;
            }
            lv_label_set_text(NormalNoTitleLblTaDesc->ContLabelTr.Label, LabelValue);

            if (NV_CONTACTS_MAX_NUMBER_LEN == g_SettingCallDivertNumberTaRestCharacters)
            {
                NormalNoTitleLblTaDesc->ButtonCont.ButtonM.TxtId = PHONE_TEXT_ID_SEARCH;
                lv_label_set_text(lv_obj_get_child(NormalNoTitleLblTaDesc->ButtonCont.ButtonM.Button, NULL),(INT8 *)lv_lang_get_text(PHONE_TEXT_ID_SEARCH));
            }
        }
        // When text is cleared to empty, middle key: OK -> SEARCH
        else
        {
            NormalNoTitleLblTaDesc->ButtonCont.ButtonM.TxtId = PHONE_TEXT_ID_SEARCH;
            lv_label_set_text(lv_obj_get_child(NormalNoTitleLblTaDesc->ButtonCont.ButtonM.Button, NULL),(INT8 *)lv_lang_get_text(PHONE_TEXT_ID_SEARCH));
        }

        return(0);

    case KEY_SOFTLEFT:  // BACK

        Nav_Back(ACT_ID_SETTING_CALL_DIVERT_NUMBER);

        return(1);

    case KEY_0:
    case KEY_1:
    case KEY_2:
    case KEY_3:
    case KEY_4:
    case KEY_5:
    case KEY_6:
    case KEY_7:
    case KEY_8:
    case KEY_9:
        // When text leaved empty state, middle key: SEARCH -> OK
        if (g_SettingCallDivertNumberTaRestCharacters == NV_CONTACTS_MAX_NUMBER_LEN)
        {
            NormalNoTitleLblTaDesc->ButtonCont.ButtonM.TxtId = PHONE_TEXT_ID_OK;
            lv_label_set_text(lv_obj_get_child(NormalNoTitleLblTaDesc->ButtonCont.ButtonM.Button, NULL),(INT8 *)lv_lang_get_text(PHONE_TEXT_ID_OK));
        }

        if (g_SettingCallDivertNumberTaRestCharacters > 0)
        {
            g_SettingCallDivertNumberTaRestCharacters--;
            if (g_SettingCallDivertNumberTaRestCharacters > 9)
            {
                LabelValue[0] = g_SettingCallDivertNumberTaRestCharacters / 10 + 0x30;
                LabelValue[1] = g_SettingCallDivertNumberTaRestCharacters % 10 + 0x30;
            }
            else
            {
                LabelValue[0] = g_SettingCallDivertNumberTaRestCharacters + 0x30;
            }
            lv_label_set_text(NormalNoTitleLblTaDesc->ContLabelTr.Label, LabelValue);
        }

        return(0);

    case KEY_END:
        Nav_Home(ACT_ID_ANY);
        return(1);

    default:
        return(0);
    } /* switch */
}     /* Display_Setting_Call_Divert_Number_KeyCb */

/**
 * display Setting_Call_Divert_Number
 * param (in) void:
 * return void:
 */
VOID Display_Setting_Call_Divert_Number(VOID)
{
    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc;
    Nav_Func_List_t                   FuncList;

    NormalNoTitleLblTaDesc = (UI_Normal_NoTitle_Label_Ta_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_NoTitle_Label_Ta_Desc_t));
    Hal_Mem_Set(NormalNoTitleLblTaDesc, 0, sizeof(UI_Normal_NoTitle_Label_Ta_Desc_t));

#define _INPUT_METHOD_FUNCTION_SUPPORTED_    0
#if _INPUT_METHOD_FUNCTION_SUPPORTED_
    UINT8 IME_Mode;

    IME_Mode = IME_MODE_123_NUMBER;
    IME_SetInputMethodMode(IME_Mode);
    NormalNoTitleLblTaDesc->ContLabelTl.TxtId = PHONE_TEXT_ID_123_NUMBER;
#endif

    NormalNoTitleLblTaDesc->ContLabelTl.TxtId       = LV_LANG_TXT_ID_NONE;
    NormalNoTitleLblTaDesc->ContLabelTl.SymbolId    = LV_SYMBOL_EDIT;
    NormalNoTitleLblTaDesc->ContLabelTl.SymbolAlign = LV_LABEL_ALIGN_LEFT;

    // NormalNoTitleLblTaDesc->ContLabelTr.TxtId = ;     //Set in OnCreate() handling
    NormalNoTitleLblTaDesc->ContLabelTr.TxtAlign = LV_LABEL_ALIGN_RIGHT;

    NormalNoTitleLblTaDesc->ContLabel.TxtId    = PHONE_TEXT_ID_PHONE_NUM;
    NormalNoTitleLblTaDesc->ContLabel.TxtAlign = LV_LABEL_ALIGN_LEFT;

    NormalNoTitleLblTaDesc->ContTa.TaTxt = Hal_Mem_Alloc(NV_CONTACTS_MAX_NUMBER_LEN);
    Hal_Mem_Set(NormalNoTitleLblTaDesc->ContTa.TaTxt, 0, NV_CONTACTS_MAX_NUMBER_LEN);

    NormalNoTitleLblTaDesc->ContTa.TaCursorHide = FALSE;
    NormalNoTitleLblTaDesc->ContTa.TaAlign      = LV_LABEL_ALIGN_LEFT;

    NormalNoTitleLblTaDesc->ButtonCont.ButtonL.Valid = TRUE;
    NormalNoTitleLblTaDesc->ButtonCont.ButtonL.TxtId = PHONE_TEXT_ID_BACK;
    NormalNoTitleLblTaDesc->ButtonCont.ButtonM.Valid = TRUE;
    NormalNoTitleLblTaDesc->ButtonCont.ButtonM.TxtId = PHONE_TEXT_ID_SEARCH;
    NormalNoTitleLblTaDesc->ButtonCont.ButtonR.Valid = TRUE;
    NormalNoTitleLblTaDesc->ButtonCont.ButtonR.TxtId = PHONE_TEXT_ID_CLEAR;

    NormalNoTitleLblTaDesc->KeyFunc = Display_Setting_Call_Divert_Number_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow         = UI_Normal_NoTitle_Label_Ta_Create;
    FuncList.OnCreate       = Display_Setting_Call_Divert_Number_Create;
    FuncList.OnDestroy      = Display_Setting_Call_Divert_Number_Destroy;
    FuncList.OnSaveState    = Display_Setting_Call_Divert_Number_SaveState;
    FuncList.OnRestoreState = Display_Setting_Call_Divert_Number_RestoreState;

    gp_SettingCallSettingCurUIDesc = (VOID *)NormalNoTitleLblTaDesc;
    Nav_Forward(ACT_ID_SETTING_CALL_DIVERT_ACTION,ACT_ID_SETTING_CALL_DIVERT_NUMBER, &FuncList, (VOID *)NormalNoTitleLblTaDesc);
} /* Display_Setting_Call_Divert_Number */

/**
 * Callback of Settings_Call_Divert_Action, Activate
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Divert_Action_Activate_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc;

        NormalLstOnlyDesc             = (UI_Normal_List_Only_Desc_t *)gp_SettingCallSettingCurUIDesc;
        NormalLstOnlyDesc->List.Index = 0;

        Setting_Set_Operating_Ss_Action(SETTING_DIVERT_ACTION_ACTIVE);
        Display_Setting_Call_Divert_Number();
    }
}

/**
 * Callback of Settings_Call_Divert_Action, Cancel
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Divert_Action_Cancel_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_Normal_List_Only_Desc_t    *NormalLstOnlyDesc;
        MMI_Modem_Call_Forward_Info_t *CallForwardInfo;

        NormalLstOnlyDesc             = (UI_Normal_List_Only_Desc_t *)gp_SettingCallSettingCurUIDesc;
        NormalLstOnlyDesc->List.Index = 1;

        Setting_Set_Operating_Ss_Action(SETTING_DIVERT_ACTION_CANCEL);

        CallForwardInfo = (MMI_Modem_Call_Forward_Info_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Call_Forward_Info_t));

        CallForwardInfo->CallForwardOn = FALSE;
        if (SETTING_DIVERT_NO_CONDITION == g_SettingCallSettingMng.OperatingSS)
        {
            CallForwardInfo->CallForwardType = MMI_MODEM_CALL_FORWARD_NO_CONDITION;
        }
        else if (SETTING_DIVERT_IF_BUSY == g_SettingCallSettingMng.OperatingSS)
        {
            CallForwardInfo->CallForwardType = MMI_MODEM_CALL_FORWARD_BUSY;
        }
        else if (SETTING_DIVERT_IF_NOT_REACH == g_SettingCallSettingMng.OperatingSS)
        {
            CallForwardInfo->CallForwardType = MMI_MODEM_CALL_FORWARD_NOT_REACH;
        }
        else if (SETTING_DIVERT_IF_NO_ANSWER == g_SettingCallSettingMng.OperatingSS)
        {
            CallForwardInfo->CallForwardType = MMI_MODEM_CALL_FORWARD_NO_ANSWER;
        }
        MMI_Modem_Call_Forward_Set_Req(g_SettingCallSettingMng.OperationSimId, CallForwardInfo);
    }
}

/**
 * Callback of Settings_Call_Divert_Action, Check status
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Divert_Action_CheckStatus_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_Normal_List_Only_Desc_t  *NormalLstOnlyDesc;
        MMI_MODEM_CALL_FORWARD_TYPE CallForwardType;

        NormalLstOnlyDesc             = (UI_Normal_List_Only_Desc_t *)gp_SettingCallSettingCurUIDesc;
        NormalLstOnlyDesc->List.Index = 2;

        Setting_Set_Operating_Ss_Action(SETTING_DIVERT_ACTION_CHECK_STATUS);

        if (SETTING_DIVERT_NO_CONDITION == g_SettingCallSettingMng.OperatingSS)
        {
            CallForwardType = MMI_MODEM_CALL_FORWARD_NO_CONDITION;
        }
        else if (SETTING_DIVERT_IF_BUSY == g_SettingCallSettingMng.OperatingSS)
        {
            CallForwardType = MMI_MODEM_CALL_FORWARD_BUSY;
        }
        else if (SETTING_DIVERT_IF_NOT_REACH == g_SettingCallSettingMng.OperatingSS)
        {
            CallForwardType = MMI_MODEM_CALL_FORWARD_NOT_REACH;
        }
        else if (SETTING_DIVERT_IF_NO_ANSWER == g_SettingCallSettingMng.OperatingSS)
        {
            CallForwardType = MMI_MODEM_CALL_FORWARD_NO_ANSWER;
        }
        else
        {   // to remove warning
            CallForwardType = MMI_MODEM_CALL_FORWARD_NO_CONDITION;
        }

        MMI_Modem_Call_Forward_Query_Req(g_SettingCallSettingMng.OperationSimId, CallForwardType);
    }
}

/**
 * Callback of Settings_Call_Divert_Action, Select delay time
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Divert_Action_SelectDelayTime_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc;

        NormalLstOnlyDesc             = (UI_Normal_List_Only_Desc_t *)gp_SettingCallSettingCurUIDesc;
        NormalLstOnlyDesc->List.Index = 3;

        Setting_Set_Operating_Ss_Action(SETTING_DIVERT_ACTION_SELECT_DELAY_TIME);
        Display_Setting_Call_Divert_Delay_Time();
    }
}

/**
 *
 * Callback of Setting_Call_Divert_Action, on destroy
 * param (in) NormalLstOnlyDesc: UI_Normal_List_Only_Desc_t*
 * return void:
 */
VOID Display_Setting_Call_Divert_Action_Destroy(VOID *pPara)
{
    UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc = NULL;

    NormalLstOnlyDesc = (UI_Normal_List_Only_Desc_t *)pPara;

    Hal_Mem_Free(NormalLstOnlyDesc->List.ButtonList);
    Hal_Mem_Free(NormalLstOnlyDesc);
}

/**
 *
 * Callback of Setting_Call_Divert_Action, KeyCb
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Call_Divert_Action_KeyCb(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    if (KEY_RELEASED != key_sta)
    {
        return(0);
    }

    if (KEY_SOFTRIGHT == key_val)
    {
        Nav_Back(ACT_ID_SETTING_CALL_DIVERT_ACTION);
        return(1);
    }
    else if (KEY_END == key_val)
    {
        Nav_Home(ACT_ID_ANY);
        return(1);
    }
    else
    {
        return(0);
    }
}

/**
 * display Settings_Call_Divert_Action
 * param (in) TitleTxtId             : UI_PHONE_TEXT_ID, the text shown on title
 *       (in) SelectDelayTimeEnabled : BOOL, "select delay time" item enabled or not
 * return void:
 */
VOID Display_Setting_Call_Divert_Action(UI_PHONE_TEXT_ID TitleTxtId, BOOL SelectDelayTimeEnabled)
{
    UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc;
    Nav_Func_List_t            FuncList;

    NormalLstOnlyDesc = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(NormalLstOnlyDesc, 0, sizeof(UI_Normal_List_Only_Desc_t));

    NormalLstOnlyDesc->TitleBar.TxtId      = TitleTxtId;
    NormalLstOnlyDesc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    NormalLstOnlyDesc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    NormalLstOnlyDesc->List.Index = 0;
    if (TRUE == SelectDelayTimeEnabled)
    {
        NormalLstOnlyDesc->List.ListButtonCnt = 4;
        NormalLstOnlyDesc->List.ButtonList    = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * 4);
        Hal_Mem_Set(NormalLstOnlyDesc->List.ButtonList, 0, sizeof(UI_Button_Desc_t) * 4);

        NormalLstOnlyDesc->List.ButtonList[3].ButtonIndex = 3;
        NormalLstOnlyDesc->List.ButtonList[3].Valid       = TRUE;
        NormalLstOnlyDesc->List.ButtonList[3].TxtId       = PHONE_TEXT_ID_SELECT_DELAY_TIME;
        NormalLstOnlyDesc->List.ButtonList[3].ReleaseFun  = Display_Setting_Call_Divert_Action_SelectDelayTime_Cb;
    }
    else
    {
        NormalLstOnlyDesc->List.ListButtonCnt = 3;
        NormalLstOnlyDesc->List.ButtonList    = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * 3);
        Hal_Mem_Set(NormalLstOnlyDesc->List.ButtonList, 0, sizeof(UI_Button_Desc_t) * 3);
    }
    NormalLstOnlyDesc->List.ButtonList[0].ButtonIndex = 0;
    NormalLstOnlyDesc->List.ButtonList[0].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[0].TxtId       = PHONE_TEXT_ID_ACTIVE;
    NormalLstOnlyDesc->List.ButtonList[0].ReleaseFun  = Display_Setting_Call_Divert_Action_Activate_Cb;
    NormalLstOnlyDesc->List.ButtonList[1].ButtonIndex = 1;
    NormalLstOnlyDesc->List.ButtonList[1].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[1].TxtId       = PHONE_TEXT_ID_CANCEL_DIVERT;
    NormalLstOnlyDesc->List.ButtonList[1].ReleaseFun  = Display_Setting_Call_Divert_Action_Cancel_Cb;
    NormalLstOnlyDesc->List.ButtonList[2].ButtonIndex = 2;
    NormalLstOnlyDesc->List.ButtonList[2].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[2].TxtId       = PHONE_TEXT_ID_CHECK_STATUS;
    NormalLstOnlyDesc->List.ButtonList[2].ReleaseFun  = Display_Setting_Call_Divert_Action_CheckStatus_Cb;

    NormalLstOnlyDesc->BtnBar.ButtonL.Valid = FALSE;
    NormalLstOnlyDesc->BtnBar.ButtonM.Valid = TRUE;
    NormalLstOnlyDesc->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    NormalLstOnlyDesc->BtnBar.ButtonR.Valid = TRUE;
    NormalLstOnlyDesc->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    NormalLstOnlyDesc->KeyFunc = Display_Setting_Call_Divert_Action_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow    = UI_Normal_List_Only_Create;
    FuncList.OnDestroy = Display_Setting_Call_Divert_Action_Destroy;

    gp_SettingCallSettingCurUIDesc = (VOID *)NormalLstOnlyDesc;
    Nav_Forward(ACT_ID_SETTING_CALL_DIVERT,ACT_ID_SETTING_CALL_DIVERT_ACTION, &FuncList, (VOID *)NormalLstOnlyDesc);
} /* Display_Setting_Call_Divert_Action */

/**
 * Callback of Settings_Call_Divert, divert all incoming call
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Divert_All_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc;

        NormalLstOnlyDesc             = (UI_Normal_List_Only_Desc_t *)gp_SettingCallSettingCurUIDesc;
        NormalLstOnlyDesc->List.Index = 0;

        Setting_Set_Operating_Ss(SETTING_DIVERT_NO_CONDITION);
        Display_Setting_Call_Divert_Action(PHONE_TEXT_ID_DIVERT_ALL, FALSE);
    }
}

/**
 * Callback of Settings_Call_Divert, divert if busy
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Divert_Busy_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc;

        NormalLstOnlyDesc             = (UI_Normal_List_Only_Desc_t *)gp_SettingCallSettingCurUIDesc;
        NormalLstOnlyDesc->List.Index = 1;

        Setting_Set_Operating_Ss(SETTING_DIVERT_IF_BUSY);
        Display_Setting_Call_Divert_Action(PHONE_TEXT_ID_DIVERT_BUSY, FALSE);
    }
}

/**
 * Callback of Settings_Call_Divert, divert if not answered
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Divert_Not_Answer_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc;

        NormalLstOnlyDesc             = (UI_Normal_List_Only_Desc_t *)gp_SettingCallSettingCurUIDesc;
        NormalLstOnlyDesc->List.Index = 2;

        Setting_Set_Operating_Ss(SETTING_DIVERT_IF_NO_ANSWER);
        Display_Setting_Call_Divert_Action(PHONE_TEXT_ID_DIVERT_NOT_ANS, TRUE);
    }
}

/**
 * Callback of Settings_Call_Divert, divert if not reach
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Divert_Out_Reach_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc;

        NormalLstOnlyDesc             = (UI_Normal_List_Only_Desc_t *)gp_SettingCallSettingCurUIDesc;
        NormalLstOnlyDesc->List.Index = 3;

        Setting_Set_Operating_Ss(SETTING_DIVERT_IF_NOT_REACH);
        Display_Setting_Call_Divert_Action(PHONE_TEXT_ID_DIVERT_OUT_REACH, FALSE);
    }
}

/**
 * Callback of Settings_Call_Divert, cancel all diverts
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Divert_Cancel_All_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_Normal_List_Only_Desc_t    *NormalLstOnlyDesc;
        MMI_Modem_Call_Forward_Info_t *CallForwardInfo;

        NormalLstOnlyDesc             = (UI_Normal_List_Only_Desc_t *)gp_SettingCallSettingCurUIDesc;
        NormalLstOnlyDesc->List.Index = 4;

        Setting_Set_Operating_Ss(SETTING_DIVERT_CANCEL_ALL);

        CallForwardInfo = (MMI_Modem_Call_Forward_Info_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Call_Forward_Info_t));
        Hal_Mem_Set(CallForwardInfo, 0, sizeof(MMI_Modem_Call_Forward_Info_t));
        CallForwardInfo->CallForwardOn   = FALSE;
        CallForwardInfo->CallForwardType = MMI_MODEM_CALL_FORWARD_CANCEL_All;
        MMI_Modem_Call_Forward_Set_Req(g_SettingCallSettingMng.OperationSimId, CallForwardInfo);
    }
}

/**
 *
 * Callback of Setting_Call_Divert, on destroy
 * param (in) NormalLstOnlyDesc: UI_Normal_List_Only_Desc_t*
 * return void:
 */
VOID Display_Setting_Call_Divert_Destroy(VOID *pPara)
{
    UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc = NULL;

    NormalLstOnlyDesc = (UI_Normal_List_Only_Desc_t *)pPara;

    Hal_Mem_Free(NormalLstOnlyDesc->List.ButtonList);
    Hal_Mem_Free(NormalLstOnlyDesc);
}

/**
 *
 * Callback of Setting_Call_Divert, on restore state
 * param (in) NormalLstOnlyDesc: VOID*
 * return void:
 */
VOID Display_Setting_Call_Divert_RestoreState(VOID *NormalLstOnlyDesc)
{
    gp_SettingCallSettingCurUIDesc = (VOID *)NormalLstOnlyDesc;
}

/**
 *
 * Callback of Setting_Call_Divert, KeyCb
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Call_Divert_KeyCb(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    if (KEY_RELEASED != key_sta)
    {
        return(0);
    }

    if (KEY_SOFTRIGHT == key_val)
    {
        Nav_Back(ACT_ID_SETTING_CALL_DIVERT);
        return(1);
    }
    else if (KEY_END == key_val)
    {
        Nav_Home(ACT_ID_ANY);
        return(1);
    }
    else
    {
        return(0);
    }
}

/**
 * display Settings_Call_Divert
 * param (in) SimId: MMI_MODEM_SIM_ID
 * return void:
 */
VOID Display_Setting_Call_Divert(MMI_MODEM_SIM_ID SimId)
{
    UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc;
    Nav_Func_List_t            FuncList;

    Setting_Set_Operation_Sim_Id(SimId);

    NormalLstOnlyDesc = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(NormalLstOnlyDesc, 0, sizeof(UI_Normal_List_Only_Desc_t));

    NormalLstOnlyDesc->TitleBar.TxtId      = PHONE_TEXT_ID_CALL_DIVERT;
    NormalLstOnlyDesc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    NormalLstOnlyDesc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    NormalLstOnlyDesc->List.Index         = 0;
    NormalLstOnlyDesc->List.ListButtonCnt = 5;
    NormalLstOnlyDesc->List.ButtonList    = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * 5);
    Hal_Mem_Set(NormalLstOnlyDesc->List.ButtonList, 0, sizeof(UI_Button_Desc_t) * 5);

    NormalLstOnlyDesc->List.ButtonList[0].ButtonIndex = 0;
    NormalLstOnlyDesc->List.ButtonList[0].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[0].TxtId       = PHONE_TEXT_ID_DIVERT_ALL;
    NormalLstOnlyDesc->List.ButtonList[0].ReleaseFun  = Display_Setting_Call_Divert_All_Cb;
    NormalLstOnlyDesc->List.ButtonList[1].ButtonIndex = 1;
    NormalLstOnlyDesc->List.ButtonList[1].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[1].TxtId       = PHONE_TEXT_ID_DIVERT_BUSY;
    NormalLstOnlyDesc->List.ButtonList[1].ReleaseFun  = Display_Setting_Call_Divert_Busy_Cb;
    NormalLstOnlyDesc->List.ButtonList[2].ButtonIndex = 2;
    NormalLstOnlyDesc->List.ButtonList[2].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[2].TxtId       = PHONE_TEXT_ID_DIVERT_NOT_ANS;
    NormalLstOnlyDesc->List.ButtonList[2].ReleaseFun  = Display_Setting_Call_Divert_Not_Answer_Cb;
    NormalLstOnlyDesc->List.ButtonList[3].ButtonIndex = 3;
    NormalLstOnlyDesc->List.ButtonList[3].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[3].TxtId       = PHONE_TEXT_ID_DIVERT_OUT_REACH;
    NormalLstOnlyDesc->List.ButtonList[3].ReleaseFun  = Display_Setting_Call_Divert_Out_Reach_Cb;
    NormalLstOnlyDesc->List.ButtonList[4].ButtonIndex = 4;
    NormalLstOnlyDesc->List.ButtonList[4].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[4].TxtId       = PHONE_TEXT_ID_CANCEL_ALL_DIVERTS;
    NormalLstOnlyDesc->List.ButtonList[4].ReleaseFun  = Display_Setting_Call_Divert_Cancel_All_Cb;

    NormalLstOnlyDesc->BtnBar.ButtonL.Valid = FALSE;
    NormalLstOnlyDesc->BtnBar.ButtonM.Valid = TRUE;
    NormalLstOnlyDesc->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    NormalLstOnlyDesc->BtnBar.ButtonR.Valid = TRUE;
    NormalLstOnlyDesc->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    NormalLstOnlyDesc->KeyFunc = Display_Setting_Call_Divert_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow         = UI_Normal_List_Only_Create;
    FuncList.OnDestroy      = Display_Setting_Call_Divert_Destroy;
    FuncList.OnRestoreState = Display_Setting_Call_Divert_RestoreState;

    gp_SettingCallSettingCurUIDesc = (VOID *)NormalLstOnlyDesc;
    Nav_Forward(ACT_ID_SETTING_SIM_SELECTION, ACT_ID_SETTING_CALL_DIVERT, &FuncList, (VOID *)NormalLstOnlyDesc);
} /* Display_Setting_Call_Divert */

/**
 * configure SS service call wait confirm
 * param (in) SimId : MMI_MODEM_SIM_ID
 * param (in) CallWaitOn : BOOL (true means call wait on)
 * return void:
 */
VOID Phone_Modem_Call_Wait_Set_Cnf(MMI_MODEM_SIM_ID SimId, MMI_MODEM_RESULT Result)
{
    // get the screen description of "Setting_Call_SIM_selection"
    if (MMI_MODEM_ERROR == Result)
    {
        Display_Setting_Error(ACT_ID_SETTING_ON_OFF,PHONE_TEXT_ID_NOT_COMPLETED,ACT_ID_SETTING_SIM_SELECTION,TRUE);
    }
    else
    {
        // update ON/OFF text id for SIM selection screen
        if (MMI_MODEM_SIM_1 == g_SettingCallSettingMng.OperationSimId)
        {
            if (1 == g_SettingCallWaitStatus[0])
            {   // ON->OFF
                g_SettingCallWaitStatus[0] = 0;
                Display_Setting_SIM_Selection_Set(PHONE_TEXT_ID_OFF, LV_LANG_TXT_ID_NONE, NULL, NULL);
            }
            else
            {   // OFF->ON
                g_SettingCallWaitStatus[0] = 1;
                Display_Setting_SIM_Selection_Set(PHONE_TEXT_ID_ON, LV_LANG_TXT_ID_NONE, NULL, NULL);
            }
        }
        else
        {
            if (1 == g_SettingCallWaitStatus[1])
            {   // ON->OFF
                g_SettingCallWaitStatus[1] = 0;
                Display_Setting_SIM_Selection_Set(LV_LANG_TXT_ID_NONE, PHONE_TEXT_ID_OFF, NULL, NULL);
            }
            else
            {   // OFF->ON
                g_SettingCallWaitStatus[1] = 1;
                Display_Setting_SIM_Selection_Set(LV_LANG_TXT_ID_NONE, PHONE_TEXT_ID_ON, NULL, NULL);
            }
        }
        Display_Setting_Done(ACT_ID_SETTING_ON_OFF, PHONE_TEXT_ID_DONE, ACT_ID_SETTING_SIM_SELECTION);
    }
} /* MMI_Modem_Call_Wait_Set_Cnf */

/**
 * Callback of Setting_Call_Wait, ON buttion
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Wait_On_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        if (MMI_MODEM_SIM_1 == g_SettingCallSettingMng.OperationSimId)
        {
            if (0 == g_SettingCallWaitStatus[0])
            {
                MMI_Modem_Call_Wait_Set_Req(MMI_MODEM_SIM_1, TRUE);
            }
            else
            {
                Display_Setting_Done(ACT_ID_SETTING_ON_OFF, PHONE_TEXT_ID_DONE, ACT_ID_SETTING_SIM_SELECTION);
            }
        }
        else
        {
            if (0 == g_SettingCallWaitStatus[1])
            {
                MMI_Modem_Call_Wait_Set_Req(MMI_MODEM_SIM_2, TRUE);
            }
            else
            {
                Display_Setting_Done(ACT_ID_SETTING_ON_OFF, PHONE_TEXT_ID_DONE, ACT_ID_SETTING_SIM_SELECTION);
            }
        }
    }
}

/**
 * Callback of Setting_Call_Wait, OFF buttion
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Wait_Off_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        if (MMI_MODEM_SIM_1 == g_SettingCallSettingMng.OperationSimId)
        {
            if (1 == g_SettingCallWaitStatus[0])
            {
                MMI_Modem_Call_Wait_Set_Req(MMI_MODEM_SIM_1, FALSE);
            }
            else
            {
                Display_Setting_Done(ACT_ID_SETTING_ON_OFF, PHONE_TEXT_ID_DONE, ACT_ID_SETTING_SIM_SELECTION);
            }
        }
        else
        {
            if (1 == g_SettingCallWaitStatus[1])
            {
                MMI_Modem_Call_Wait_Set_Req(MMI_MODEM_SIM_2, FALSE);
            }
            else
            {
                Display_Setting_Done(ACT_ID_SETTING_ON_OFF, PHONE_TEXT_ID_DONE, ACT_ID_SETTING_SIM_SELECTION);
            }
        }
    }
}

/**
 * display Settings_Call_Wait
 * param (in) SimId: MMI_MODEM_SIM_ID
 * return void:
 */
VOID Display_Setting_Call_Wait(MMI_MODEM_SIM_ID SimId)
{
    Setting_Set_Operation_Sim_Id(SimId);
    if (MMI_MODEM_SIM_1 == SimId)
    {
        Display_Setting_On_Off(ACT_ID_SETTING_SIM_SELECTION,PHONE_TEXT_ID_CALL_WAITING,g_SettingCallWaitStatus[0],Display_Setting_Call_Wait_On_Cb,Display_Setting_Call_Wait_Off_Cb);
    }
    else
    {
        Display_Setting_On_Off(ACT_ID_SETTING_SIM_SELECTION,PHONE_TEXT_ID_CALL_WAITING,g_SettingCallWaitStatus[1],Display_Setting_Call_Wait_On_Cb,Display_Setting_Call_Wait_Off_Cb);
    }
}

/**
 * query SS service call wait confirm
 * param (in) SimId : MMI_MODEM_SIM_ID
 * param (in) CallWaitOn : BOOL
 * param (in) Resutl : MMI_MODEM_RESULT
 * return void
 */
VOID Phone_Modem_Call_Wait_Query_Cnf(MMI_MODEM_SIM_ID SimId, BOOL CallWaitOn, MMI_MODEM_RESULT Result)
{
    UI_PHONE_TEXT_ID Sim1_CallWaitStatus_TxtId;
    UI_PHONE_TEXT_ID Sim2_CallWaitStatus_TxtId;

    if (MMI_MODEM_ERROR == Result)
    {
        Display_Setting_Error(ACT_ID_SETTING_CALL_SETTINGS,PHONE_TEXT_ID_NOT_COMPLETED,ACT_ID_SETTING_CALL_SETTINGS,TRUE);
        return;
    }

    if (MMI_MODEM_SIM_1 == SimId)
    {
        g_SettingCallWaitStatus[0]     = (CallWaitOn == TRUE) ? 1 : 0;
        g_SettingCallWaitWaitQueryCnf &= ~0x01;
    }
    else if (MMI_MODEM_SIM_2 == SimId)
    {
        g_SettingCallWaitStatus[1]     = (CallWaitOn == TRUE) ? 1 : 0;
        g_SettingCallWaitWaitQueryCnf &= ~0x02;
    }

    // if the other query operation is on-going, continue waiting
    if (0 != g_SettingCallWaitWaitQueryCnf)
    {
        return;
    }

    // display the SIM selection screen
    if (TRUE == g_SettingSimStatus[MMI_MODEM_SIM_1])    // sim1 present
    {
        // set ON/OFF text id for status display
        if (0 == g_SettingCallWaitStatus[0])
        {
            Sim1_CallWaitStatus_TxtId = PHONE_TEXT_ID_OFF;
        }
        else
        {
            Sim1_CallWaitStatus_TxtId = PHONE_TEXT_ID_ON;
        }
    }
    else
    {
        Sim1_CallWaitStatus_TxtId = LV_LANG_TXT_ID_NONE;
    }

    if (TRUE == g_SettingSimStatus[MMI_MODEM_SIM_2])    // sim2 present
    {
        // set ON/OFF text id for status display
        if (0 == g_SettingCallWaitStatus[1])
        {
            Sim2_CallWaitStatus_TxtId = PHONE_TEXT_ID_OFF;
        }
        else
        {
            Sim2_CallWaitStatus_TxtId = PHONE_TEXT_ID_ON;
        }
    }
    else
    {
        Sim2_CallWaitStatus_TxtId = LV_LANG_TXT_ID_NONE;
    }

    Display_Setting_SIM_Selection(ACT_ID_SETTING_CALL_SETTINGS,Sim1_CallWaitStatus_TxtId,Sim2_CallWaitStatus_TxtId,NULL,NULL,Display_Setting_Call_Wait);
} /* MMI_Modem_Call_Wait_Query_Cnf */

/**
 * Callback Function of Setting_SIM_Selection of Setting_Call_Divert
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_SIM_Selection_Call_Divert_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        Display_Setting_SIM_Selection(ACT_ID_SETTING_CALL_SETTINGS,LV_LANG_TXT_ID_NONE,LV_LANG_TXT_ID_NONE,NULL,NULL,Display_Setting_Call_Divert);
    }
}

/**
 * Callback of Setting_Call_AutoRedial, ON buttion
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_AutoRedial_On_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_Normal_Container_List_Desc_t *pNormalContLstDesc = NULL;

        pNormalContLstDesc                                                                            = (UI_Normal_Container_List_Desc_t *)gp_SettingCallSettingCurContLstUIDesc;
        pNormalContLstDesc->ContList.ContainerList[pNormalContLstDesc->ContList.Index].u.Label2.TxtId = PHONE_TEXT_ID_ON;

        Setting_Set_Redial_Config(TRUE);
        Display_Setting_Done(ACT_ID_SETTING_ON_OFF, PHONE_TEXT_ID_DONE, ACT_ID_SETTING_CALL_SETTINGS);
    }
}

/**
 * Callback of Setting_Call_AutoRedial, OFF buttion
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_AutoRedial_Off_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_Normal_Container_List_Desc_t *pNormalContLstDesc = NULL;

        pNormalContLstDesc                                                                            = (UI_Normal_Container_List_Desc_t *)gp_SettingCallSettingCurContLstUIDesc;
        pNormalContLstDesc->ContList.ContainerList[pNormalContLstDesc->ContList.Index].u.Label2.TxtId = PHONE_TEXT_ID_OFF;

        Setting_Set_Redial_Config(FALSE);
        Display_Setting_Done(ACT_ID_SETTING_ON_OFF, PHONE_TEXT_ID_DONE, ACT_ID_SETTING_CALL_SETTINGS);
    }
}

/**
 * Callback Function of Setting_Attomatic_Redial
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Automatic_Redial_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        if (TRUE == g_SettingCallSettingMng.AutoRedialOn)
        {
            Display_Setting_On_Off(ACT_ID_SETTING_CALL_SETTINGS, PHONE_TEXT_ID_AUTO_REDIAL, 1,Display_Setting_Call_AutoRedial_On_Cb,Display_Setting_Call_AutoRedial_Off_Cb);
        }
        else
        {
            Display_Setting_On_Off(ACT_ID_SETTING_CALL_SETTINGS, PHONE_TEXT_ID_AUTO_REDIAL, 0,Display_Setting_Call_AutoRedial_On_Cb,Display_Setting_Call_AutoRedial_Off_Cb);
        }
    }
}

/**
 * Callback Function of Setting_Attomatic_Redial
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Call_Waiting_Service_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_PHONE_TEXT_ID Sim1_CallWaitStatus_TxtId;
        UI_PHONE_TEXT_ID Sim2_CallWaitStatus_TxtId;

        // sim1 present
        if (TRUE == g_SettingSimStatus[MMI_MODEM_SIM_1])
        {
            // call wait status is present
            if (0xFF != g_SettingCallWaitStatus[0])
            {
                // set ON/OFF text id for status display
                if (0 == g_SettingCallWaitStatus[0])
                {
                    Sim1_CallWaitStatus_TxtId = PHONE_TEXT_ID_OFF;
                }
                else
                {
                    Sim1_CallWaitStatus_TxtId = PHONE_TEXT_ID_ON;
                }
            }
            // call wait status is absent, then send MMI command to check the status
            else
            {
                MMI_Modem_Call_Wait_Query_Req(MMI_MODEM_SIM_1);
                g_SettingCallWaitWaitQueryCnf |= 0x01;
            }
        }
        // sim1 absent
        else
        {
            Sim1_CallWaitStatus_TxtId = LV_LANG_TXT_ID_NONE;
        }

        // sim2 present
        if (TRUE == g_SettingSimStatus[MMI_MODEM_SIM_2])
        {
            // call wait status is present
            if (0xFF != g_SettingCallWaitStatus[1])
            {
                // set ON/OFF text id for status display
                if (0 == g_SettingCallWaitStatus[1])
                {
                    Sim2_CallWaitStatus_TxtId = PHONE_TEXT_ID_OFF;
                }
                else
                {
                    Sim2_CallWaitStatus_TxtId = PHONE_TEXT_ID_ON;
                }
            }
            // call wait status is absent, then send MMI command to check the status
            else
            {
                MMI_Modem_Call_Wait_Query_Req(MMI_MODEM_SIM_2);
                g_SettingCallWaitWaitQueryCnf |= 0x02;
            }
        }
        // SIM2 absent
        else
        {
            Sim2_CallWaitStatus_TxtId = LV_LANG_TXT_ID_NONE;
        }

        // if no modem query operation, display SIM selection screen immediately, else waiting for query cnf
        if (0 == g_SettingCallWaitWaitQueryCnf)
        {
            Display_Setting_SIM_Selection(ACT_ID_SETTING_CALL_SETTINGS,Sim1_CallWaitStatus_TxtId,Sim2_CallWaitStatus_TxtId,NULL,NULL,Display_Setting_Call_Wait);
        }
    }
} /* Display_Setting_Call_Waiting_Service_Cb */

/**
 * Callback Function of Setting_Attomatic_Redial
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_No_Screening_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        Contacts_Enter_Num_Scrn_List_Req();
    }
}

/**
 *
 * Callback of Settings_Call_Settings, on destroy
 * param (in) pNormalContLstDesc: UI_Normal_Container_List_Desc_t*
 * return void:
 */
VOID Display_Setting_Call_Settings_Destroy(VOID *pPara)
{
    UI_Normal_Container_List_Desc_t *pNormalContLstDesc = NULL;

    pNormalContLstDesc = (UI_Normal_Container_List_Desc_t *)pPara;

    Hal_Mem_Free(pNormalContLstDesc->ContList.ContainerList);
    Hal_Mem_Free(pNormalContLstDesc);
}

/**
 *
 * Callback of Setting_Call_Settings, on restore state
 * param (in) pNormalContLstDesc: UI_Normal_Container_List_Desc_t*
 * return void:
 */
VOID Display_Setting_Call_Settings_RestoreState(VOID *pNormalContLstDesc)
{
    gp_SettingCallSettingCurContLstUIDesc = pNormalContLstDesc;
}

/**
 *
 * Callback of Setting_Call_Settings, KeyCb
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Call_Settings_KeyCb(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UI_Normal_Container_List_Desc_t *pNormalContLstDesc;

    if (KEY_RELEASED != key_sta)
    {
        return(0);
    }

    pNormalContLstDesc = (UI_Normal_Container_List_Desc_t *)gp_SettingCallSettingCurContLstUIDesc;

    if (KEY_DOWN == key_val)
    {
        pNormalContLstDesc->ContList.Index++;
        pNormalContLstDesc->ContList.Index %= pNormalContLstDesc->ContList.ListContainerCnt;
        return(0);
    }
    else if (KEY_UP == key_val)
    {
        pNormalContLstDesc->ContList.Index += pNormalContLstDesc->ContList.ListContainerCnt;
        pNormalContLstDesc->ContList.Index--;
        pNormalContLstDesc->ContList.Index %= pNormalContLstDesc->ContList.ListContainerCnt;
        return(0);
    }
    else if (KEY_SOFTRIGHT == key_val)
    {
        Nav_Back(ACT_ID_ANY);
        return(1);
    }
    else if (KEY_END == key_val)
    {
        Nav_Home(ACT_ID_ANY);
        return(1);
    }
    else
    {
        return(0);
    }
} /* Display_Setting_Call_Settings_KeyCb */

/**
 * display Settings_Call_Settings
 * param (in) void:
 * return void:
 */
VOID Display_Setting_Call_Settings(VOID)
{
    Nav_Func_List_t                 FuncList;
    UI_Normal_Container_List_Desc_t *pNormalContLstDesc;
    UINT8                           i = 0;

    // Alloc memory for time setting UI display
    pNormalContLstDesc = Hal_Mem_Alloc(sizeof(UI_Normal_Container_List_Desc_t));
    Hal_Mem_Set(pNormalContLstDesc, 0, sizeof(UI_Normal_Container_List_Desc_t));

    pNormalContLstDesc->TitleBar.TxtId      = PHONE_TEXT_ID_CALL_SETTINGS;
    pNormalContLstDesc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    pNormalContLstDesc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    pNormalContLstDesc->ContList.Index = 0;

    if ((FALSE == g_SettingSimStatus[MMI_MODEM_SIM_1]) && (FALSE == g_SettingSimStatus[MMI_MODEM_SIM_2]))
    {
        pNormalContLstDesc->ContList.ListContainerCnt = 2;
        pNormalContLstDesc->ContList.ContainerList    = Hal_Mem_Alloc(sizeof(UI_Container_Base_Desc_t) * pNormalContLstDesc->ContList.ListContainerCnt);
        Hal_Mem_Set(pNormalContLstDesc->ContList.ContainerList, 0, sizeof(UI_Container_Base_Desc_t) * pNormalContLstDesc->ContList.ListContainerCnt);
    }
    else
    {
        pNormalContLstDesc->ContList.ListContainerCnt = 4;
        pNormalContLstDesc->ContList.ContainerList    = Hal_Mem_Alloc(sizeof(UI_Container_Base_Desc_t) * pNormalContLstDesc->ContList.ListContainerCnt);
        Hal_Mem_Set(pNormalContLstDesc->ContList.ContainerList, 0, sizeof(UI_Container_Base_Desc_t) * pNormalContLstDesc->ContList.ListContainerCnt);

        pNormalContLstDesc->ContList.ContainerList[i].Label.TxtId      = PHONE_TEXT_ID_CALL_DIVERT;
        pNormalContLstDesc->ContList.ContainerList[i].Label.TxtAlign   = LV_LABEL_ALIGN_LEFT;
        pNormalContLstDesc->ContList.ContainerList[i].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
        pNormalContLstDesc->ContList.ContainerList[i].Valid            = TRUE;
        pNormalContLstDesc->ContList.ContainerList[i].Choise           = UI_BASE_OBJ_NULL;
        pNormalContLstDesc->ContList.ContainerList[i++].ReleaseFunc    = Display_Setting_SIM_Selection_Call_Divert_Cb;
    }

    pNormalContLstDesc->ContList.ContainerList[i].Label.TxtId      = PHONE_TEXT_ID_AUTO_REDIAL;
    pNormalContLstDesc->ContList.ContainerList[i].Label.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    pNormalContLstDesc->ContList.ContainerList[i].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    pNormalContLstDesc->ContList.ContainerList[i].Valid            = TRUE;
    pNormalContLstDesc->ContList.ContainerList[i].Choise           = UI_BASE_OBJ_LABEL;
    if (TRUE == g_SettingCallSettingMng.AutoRedialOn)
    {
        pNormalContLstDesc->ContList.ContainerList[i].u.Label2.TxtId = PHONE_TEXT_ID_ON;
    }
    else
    {
        pNormalContLstDesc->ContList.ContainerList[i].u.Label2.TxtId = PHONE_TEXT_ID_OFF;
    }
    pNormalContLstDesc->ContList.ContainerList[i].u.Label2.TxtAlign   = LV_LABEL_ALIGN_RIGHT;
    pNormalContLstDesc->ContList.ContainerList[i].u.Label2.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    pNormalContLstDesc->ContList.ContainerList[i++].ReleaseFunc       = Display_Setting_Automatic_Redial_Cb;

    if ((TRUE == g_SettingSimStatus[MMI_MODEM_SIM_1]) || (TRUE == g_SettingSimStatus[MMI_MODEM_SIM_2]))
    {
        pNormalContLstDesc->ContList.ContainerList[i].Label.TxtId      = PHONE_TEXT_ID_CALL_WAITING;
        pNormalContLstDesc->ContList.ContainerList[i].Label.TxtAlign   = LV_LABEL_ALIGN_LEFT;
        pNormalContLstDesc->ContList.ContainerList[i].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
        pNormalContLstDesc->ContList.ContainerList[i].Choise           = UI_BASE_OBJ_NULL;
        pNormalContLstDesc->ContList.ContainerList[i].Valid            = TRUE;
        pNormalContLstDesc->ContList.ContainerList[i++].ReleaseFunc    = Display_Setting_Call_Waiting_Service_Cb;
    }

    pNormalContLstDesc->ContList.ContainerList[i].Label.TxtId      = PHONE_TEXT_ID_NSCREENING;
    pNormalContLstDesc->ContList.ContainerList[i].Label.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    pNormalContLstDesc->ContList.ContainerList[i].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    pNormalContLstDesc->ContList.ContainerList[i].Choise           = UI_BASE_OBJ_NULL;
    pNormalContLstDesc->ContList.ContainerList[i].Valid            = TRUE;
    pNormalContLstDesc->ContList.ContainerList[i].ReleaseFunc      = Display_Setting_No_Screening_Cb;

    pNormalContLstDesc->ButtonBar.ButtonL.Valid       = FALSE;
    pNormalContLstDesc->ButtonBar.ButtonM.Valid       = TRUE;
    pNormalContLstDesc->ButtonBar.ButtonM.ButtonIndex = 1;
    pNormalContLstDesc->ButtonBar.ButtonM.TxtId       = PHONE_TEXT_ID_SELECT;
    pNormalContLstDesc->ButtonBar.ButtonR.Valid       = TRUE;
    pNormalContLstDesc->ButtonBar.ButtonR.ButtonIndex = 2;
    pNormalContLstDesc->ButtonBar.ButtonR.TxtId       = PHONE_TEXT_ID_BACK;

    pNormalContLstDesc->KeyFunc = Display_Setting_Call_Settings_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow         = UI_Normal_Container_List_Create;
    FuncList.OnDestroy      = Display_Setting_Call_Settings_Destroy;
    FuncList.OnRestoreState = Display_Setting_Call_Settings_RestoreState;

    gp_SettingCallSettingCurContLstUIDesc = (VOID *)pNormalContLstDesc;
    Nav_Forward(ACT_ID_SETTING, ACT_ID_SETTING_CALL_SETTINGS, &FuncList, pNormalContLstDesc);
} /* Display_Setting_Call_Settings */

VOID Display_Setting_Call_Settings_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if(LV_EVENT_CLICKED == Event)
    {
        Display_Setting_Call_Settings();
    }
}
